<?php

class User_Form_RightForm extends Pldkp_Form 
{ 
    protected $right = null;
    
    public function __construct($right = null, $options = null)
    {
        $this->right = $right;
        parent::__construct($options);
    }
    
    public function init()
    {
        $this->setName('edit_right');
        
        $name = new Zend_Form_Element_Text('name');
        $name->setRequired(true)
              ->setLabel('Name')
              ->addValidator('NotEmpty');
        
        // Ignore the unique entry for the group itself...
        if ($this->right) {
            $name->addValidator('UniqueEntry', false, array('User_Model_Rights', 'name', array('id' => $this->right->id)));
        } else {
            $name->addValidator('UniqueEntry', false, array('User_Model_Rights', 'name'));
        }
        
        $description = new Zend_Form_Element_Textarea('description');
        $description->setLabel('Description');
   
        $submit = new Zend_Form_Element_Submit('submit');
        $submit->setLabel($this->right ? 'Edit' : 'Create');
        
        $this->addElements(array($name, $description, $submit));
    }
}